package com.ruyuan.commodity.consumer.core.receiver;

import com.ruyuan.commodity.consumer.core.event.SearchKeywordEvent;
import com.ruyuan.commodity.open.api.model.base.rabbitmq.AmqpExchange;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * 关键字搜索历史消息
 */
@Component
public class SearchKeywordReceiver {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private SearchKeywordEvent searchKeywordEvent;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = AmqpExchange.SEARCH_KEYWORDS + "_QUEUE"),
            exchange = @Exchange(value = AmqpExchange.SEARCH_KEYWORDS, type = ExchangeTypes.FANOUT)
    ))
    public void receive(String keywords) {
        searchKeywordEvent.updateOrAdd(keywords);
    }

}
